#include "BaseLoader.h"
#include "model/Track.h"
#include "algorithms/Algorithms.h"

#include <fstream>
#include <iostream>
#include <string.h>

bool BaseLoader::load(const char * fileName, HMM &hmm) {
	std::ifstream fin;
	fin.open(fileName);
	if (!fin) {
		std::cout << "Unable to load file " << fileName << "\n";
		return false;
	} else {

		fin.close();
		return true;
	}

}

bool BaseLoader::train(const char * fileName, HMM &hmm) {
	std::cout << "train model\n";
	std::ifstream fin;
	fin.open(fileName);
	if (!fin) {
		std::cout << "Unable to load file " << fileName << "\n";
		return false;
	} else {
//		char str[10];
//		fin >> str;
//		std::cout << str;
//		if (strcmp(str, "<track") == 0) {
			unsigned n;
			int x, y;
			Track track;
			Observation obs;

			fin >> n;
			std::cout << "train model: size of obs = " << n << "\n";
			//fin.getline(str, 10);
			for (unsigned i = 0; i < n; i++) {
				fin >> x >> y;
				track.addPoint(x, y);
			}
			track.convert(obs, hmm.getAlphabetSize());
			hmm.train(obs);


			std::cout << "obs: ";
			HMMALG::printUnsignedRow(obs);
			std::cout << "\n";
//		}
		fin.close();
		return true;
	}
}


